Skip to content

Adopt pure entity trees with typed relations#23

Merged
alganet merged 1 commit intoRespect:masterfrom
alganet:pk-track
Mar 26, 2026
Merged

Adopt pure entity trees with typed relations#23
alganet merged 1 commit intoRespect:masterfrom
alganet:pk-track

Conversation

@alganet
Copy link
Copy Markdown
Member

@alganet alganet commented Mar 26, 2026

EntityFactory now detects relation properties via type-hint reflection instead of naming conventions, and converts between camelCase entity properties and snake_case DB columns through the Style subsystem.

  • extractColumns() uses detectRelationProperties() to identify relations by their non-builtin type hints, replacing convention-based isRelationProperty()
  • set()/get() apply styledProperty() for DB-to-entity name conversion
  • Type coercion in set() handles numeric strings, union types, and nullability
  • Standard style styledProperty/realProperty now perform camelCase↔snake_case
  • NorthWind overrides both to preserve PascalCase as-is
  • All test stubs use typed properties: int $id (uninitialized), typed object relations (Author $author), no mixed or _id scalars

@alganet alganet marked this pull request as ready for review March 26, 2026 20:32
@alganet alganet requested a review from Copilot March 26, 2026 20:32
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 26, 2026

Codecov Report

❌ Patch coverage is 94.59459% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.67%. Comparing base (48a4ff2) to head (61c6f1a).

Files with missing lines Patch % Lines
src/EntityFactory.php 94.11% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master      #23      +/-   ##
============================================
- Coverage     98.45%   97.67%   -0.79%     
- Complexity      204      256      +52     
============================================
  Files            16       16              
  Lines           453      516      +63     
============================================
+ Hits            446      504      +58     
- Misses            7       12       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the entity mapping layer to rely on typed properties and reflection for relation detection, while also introducing Style-driven conversion between entity property names and DB column names (camelCase ↔ snake_case) and adding type coercion when hydrating entities.

Changes:

  • Update EntityFactory to detect relations via type-hint reflection, apply styledProperty() in set()/get(), and add typed coercion for scalar/union/nullability cases.
  • Update Standard style to convert property names between camelCase and snake_case; update NorthWind to preserve PascalCase properties.
  • Migrate test entities/stubs and style integration tests to typed IDs and typed object relations (no _id scalar relation fields).

Reviewed changes

Copilot reviewed 37 out of 37 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/Styles/Sakila/SakilaIntegrationTest.php Adjust new-entity PK assertion to reflect typed PK property naming.
tests/Styles/Sakila/PostCategory.php Convert join entity fields to typed PK + typed relations.
tests/Styles/Sakila/Post.php Convert entity PK and relation to typed properties.
tests/Styles/Sakila/Comment.php Convert entity PK and relation to typed properties.
tests/Styles/Sakila/Category.php Convert entity PK to typed property.
tests/Styles/Sakila/Author.php Convert entity PK to typed property.
tests/Styles/Plural/PostCategory.php Convert join entity fields to typed PK + typed relations.
tests/Styles/Plural/Post.php Convert entity PK and relation to typed properties.
tests/Styles/Plural/PluralIntegrationTest.php Adjust new-entity PK assertion for typed PK.
tests/Styles/Plural/Comment.php Convert entity PK and relation to typed properties.
tests/Styles/Plural/Category.php Convert entity PK and add typed relation property.
tests/Styles/Plural/Author.php Convert entity PK to typed property.
tests/Styles/NorthWind/Posts.php Convert entity PK and relation to typed properties (PascalCase).
tests/Styles/NorthWind/PostCategories.php Convert join entity fields to typed PK + typed relations (PascalCase).
tests/Styles/NorthWind/NorthWindIntegrationTest.php Adjust new-entity PK assertion for typed PK.
tests/Styles/NorthWind/Comments.php Convert entity PK and relation to typed properties (PascalCase).
tests/Styles/NorthWind/Categories.php Convert entity PK to typed property (PascalCase).
tests/Styles/NorthWind/Authors.php Convert entity PK to typed property (PascalCase).
tests/Styles/CakePHP/PostCategory.php Convert join entity fields to typed PK + typed relations.
tests/Styles/CakePHP/Post.php Convert entity PK and relation to typed properties.
tests/Styles/CakePHP/Comment.php Convert entity PK and relation to typed properties.
tests/Styles/CakePHP/Category.php Convert entity PK and replace scalar FK with typed relation.
tests/Styles/CakePHP/CakePHPIntegrationTest.php Adjust new-entity PK assertion for typed PK.
tests/Styles/CakePHP/Author.php Convert entity PK to typed property.
tests/Stubs/TypeCoercionEntity.php Add a new stub entity for coercion/union/nullability tests.
tests/Stubs/Post.php Convert stub PK + relation to typed properties.
tests/Stubs/Issue.php Convert stub PK to typed property.
tests/Stubs/Foo.php Convert stub PK and tighten text type to `string
tests/Stubs/Comment.php Convert stub PK + relation to typed properties.
tests/Stubs/Category.php Convert stub PK and replace scalar FK with typed relation.
tests/Stubs/Bug.php Convert stub PK to typed property.
tests/Stubs/Author.php Convert stub PK to typed property.
tests/EntityFactoryTest.php Update FK extraction tests for typed relations; add new tests for uninitialized relations and coercion behavior.
tests/AbstractMapperTest.php Remove identity-map test that relied on non-scalar PK assignment now prevented by typed PKs.
src/Styles/Standard.php Implement camelCase↔snake_case conversion for property naming.
src/Styles/NorthWind.php Override property naming conversion to preserve PascalCase.
src/EntityFactory.php Add typed-relation detection via reflection; apply styled property lookup in set/get; add coercion helpers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@alganet alganet force-pushed the pk-track branch 2 times, most recently from 7bca9ae to 78ff7d8 Compare March 26, 2026 20:57
EntityFactory now detects relation properties via type-hint reflection
instead of naming conventions, and converts between camelCase entity
properties and snake_case DB columns through the Style subsystem.

- extractColumns() uses detectRelationProperties() to identify relations
  by their non-builtin type hints, replacing convention-based isRelationProperty()
- set()/get() apply styledProperty() for DB-to-entity name conversion
- Type coercion in set() handles numeric strings, union types, and nullability
- Standard style styledProperty/realProperty now perform camelCase↔snake_case
- NorthWind overrides both to preserve PascalCase as-is
- All test stubs use typed properties: int $id (uninitialized),
  typed object relations (Author $author), no mixed or _id scalars
@alganet alganet merged commit 8f29aff into Respect:master Mar 26, 2026
3 checks passed
@alganet alganet deleted the pk-track branch March 26, 2026 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants